from selenium import webdriver
from tinyshop.common.Set_up import Setup
import time
class Sign_in:
    def __init__(self):
        self.driver=Setup().driver
        #创建注册动作函数
    def sign_user(self,email,password,re_password,verification_code):
        time.sleep(1)
        #点击登录
        self.driver.find_element_by_xpath('/html/body/div[1]/div[1]/div/div[2]/ul/li[7]/a[2]').click()
        time.sleep(1)   #等待1s
        #清除email输入框并输入email
        self.driver.find_element_by_xpath('/html/body/div[3]/div[1]/div/form/ul/li[1]/input').clear()
        self.driver.find_element_by_xpath('/html/body/div[3]/div[1]/div/form/ul/li[1]/input').send_keys(email)
        time.sleep(1)
        #清除password输入框并输入password
        self.driver.find_element_by_xpath('/html/body/div[3]/div[1]/div/form/ul/li[2]/input').clear()
        self.driver.find_element_by_xpath('/html/body/div[3]/div[1]/div/form/ul/li[2]/input').send_keys(password)
        time.sleep(1)
        #清除确认密码输入框并输入password
        self.driver.find_element_by_xpath('/html/body/div[3]/div[1]/div/form/ul/li[3]/input').clear()
        self.driver.find_element_by_xpath('/html/body/div[3]/div[1]/div/form/ul/li[3]/input').send_keys(re_password)
        time.sleep(1)
        #清除验证码输入框并输入验证码
        self.driver.find_element_by_xpath('/html/body/div[3]/div[1]/div/form/ul/li[4]/input').clear()
        self.driver.find_element_by_xpath('/html/body/div[3]/div[1]/div/form/ul/li[4]/input').send_keys(verification_code)
        #勾选同意协议
        self.driver.find_element_by_xpath('/html/body/div[3]/div[1]/div/form/ul/li[5]/dd/input').click()
        #点击注册
        self.driver.find_element_by_xpath('/html/body/div[3]/div[1]/div/form/ul/li[6]/button').click()

        #创建注册成功断言
    def assert_sign_succ(self,expect):
        if expect in self.driver.find_element_by_xpath('/html/body/div[2]/div/div[1]/span').text:
            print('pass')
        else:
            print('fail')
        self.driver.quit()
    #创建注册失败断言
    def assert_sign_fail(self,expect):
        if expect=='两次输入密码不一致'or expect=='6-20任意字符组合':
            if expect in self.driver.find_element_by_xpath('/html/body/div[3]/div[1]/div/form/ul/li[3]/label').text:
                print('pass sign fail reason is %s'%expect)
            else:
                print('fail')
        elif expect=='邮箱格式不正确' or expect=='此用户已经注册':
            if expect in self.driver.find_element_by_xpath('/html/body/div[3]/div[1]/div/form/ul/li[1]/label').text:
                print('pass sign fail reason is %s'%expect)
            else:
                print('fail')
        elif expect=='验证码错误' or expect=='验证码不正确':
            if expect in self.driver.find_element_by_xpath('/html/body/div[3]/div[1]/div/form/ul/li[4]').text:
                print('pass sign fail reason is %s'%expect)
       
        else:
                print('fail')
        self.driver.quit()

